/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelEthernet.java
 *
 * Created on 12/03/2011, 18:34:21
 */

package tsb.UI.Paneles;

import tsb.dominio.interfaces.RJ45FastEthernet;
import tsb.dominio.interfaces.IP;
import tsb.dominio.interfaces.MAC;
import tsb.dominio.excepciones.MACException;
import tsb.UI.Ventanas.VentanaDeError;
import tsb.dominio.enumeraciones.AsignacionIP;


/**
 *
 * @author Federico Gomez
 */
public class PanelRJ45Switch extends javax.swing.JPanel {

    /** Creates new form PanelEthernet */
    public PanelRJ45Switch() {
        initComponents();
    }

    public RJ45FastEthernet getRJ45FastEthernet() throws MACException
    {
        

        int anchoBanda=0;
        if(this.chkAnchoBanda.isSelected())
        {
            anchoBanda=100;
        }
        else
        {
            anchoBanda=10;
        }
        boolean duplex;
        if(this.rbDuplex.isSelected())
        {duplex=true;}
        else
        {duplex=false;}
        IP ip = new IP();
        IP subNet= new IP();
        MAC mac= new MAC("8A-CE-34-61-25-F9");
        RJ45FastEthernet fe= new RJ45FastEthernet(true,1200,ip,subNet,true,true, mac);

        return fe;
      
    }
  
    public void setAnchoBanda(int ancho)
    {
        if(ancho==100)
        {
            this.rbtn100.setSelected(true);
        }
        else
        {
            this.rbtn10.setSelected(true);
        }
    }
    public int getAnchoBanda()
    {
        if(this.rbtn100.isSelected())
        {
            return 100;
        }
        else
        {
            return 10;
        }
    }
    public boolean getDuplex()
    {
        if(this.rbFullDuplex.isSelected())
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public void setDuplex(boolean aux)
    {
        if(aux==true)
        {
            this.rbFullDuplex.setSelected(true);
            this.rbDuplex.setSelected(false);
        }
        else
        {
            this.rbDuplex.setSelected(true);
            this.rbFullDuplex.setSelected(false);
        }
    }
    
    public boolean verificar()
    {
//       if(!this.panelInterfaces.verificar())
//           return false;
//       
//       if(!this.chkAutoDuplex.isSelected())
//       {
//            if(!this.rbDuplex.isSelected())
//           {
//               if(!this.rbFullDuplex.isSelected())
//               {
//                   VentanaDeError.mostrarDialog("ERROR", "Debe seleccionar un tipo de Duplex", 2); 
//
//               }
//           }
//       }
//       
//       try
//        {
//            MAC.verificarMAC(this.txtMAC.getText());
//        }
//        catch(Exception e)
//        {
//            VentanaDeError.mostrarDialog("ERROR", "                           La MAC ingresada no es correcta.\n Debe tener el formato AA-AA-AA-AA-AA-AA con caracteres hexadecimales de 0 a F", 2);
//            return false;
//        }
       return true; 
    }
    
    public void setAsignacion(AsignacionIP asigancion)
    {
       // this.panelInterfaces.setAsignacionIP(asigancion);
        
    }
    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgroupDuplex = new javax.swing.ButtonGroup();
        jSeparator1 = new javax.swing.JSeparator();
        panelAnchoDeBanda = new javax.swing.JPanel();
        chkAnchoBanda = new javax.swing.JCheckBox();
        rbtn10 = new javax.swing.JRadioButton();
        rbtn100 = new javax.swing.JRadioButton();
        jSeparator2 = new javax.swing.JSeparator();
        panelDuplex = new javax.swing.JPanel();
        rbDuplex = new javax.swing.JRadioButton();
        rbFullDuplex = new javax.swing.JRadioButton();
        chkAutoDuplex = new javax.swing.JCheckBox();
        jSeparator3 = new javax.swing.JSeparator();
        cmbAcces = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        cmbVLAN = new javax.swing.JComboBox();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createTitledBorder("RJ-45"));

        panelAnchoDeBanda.setBackground(new java.awt.Color(255, 255, 255));
        panelAnchoDeBanda.setBorder(javax.swing.BorderFactory.createTitledBorder("Ancho de Banda"));
        panelAnchoDeBanda.setAlignmentX(0.3F);
        panelAnchoDeBanda.setAlignmentY(0.3F);

        chkAnchoBanda.setBackground(new java.awt.Color(255, 255, 255));
        chkAnchoBanda.setFont(new java.awt.Font("Tahoma", 0, 14));
        chkAnchoBanda.setSelected(true);
        chkAnchoBanda.setText("Auto");
        chkAnchoBanda.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                chkAnchoBandaMouseClicked(evt);
            }
        });

        rbtn10.setBackground(new java.awt.Color(255, 255, 255));
        rbtn10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        rbtn10.setText("10");
        rbtn10.setEnabled(false);

        rbtn100.setBackground(new java.awt.Color(255, 255, 255));
        rbtn100.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        rbtn100.setText("100");
        rbtn100.setEnabled(false);

        javax.swing.GroupLayout panelAnchoDeBandaLayout = new javax.swing.GroupLayout(panelAnchoDeBanda);
        panelAnchoDeBanda.setLayout(panelAnchoDeBandaLayout);
        panelAnchoDeBandaLayout.setHorizontalGroup(
            panelAnchoDeBandaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAnchoDeBandaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chkAnchoBanda)
                .addGap(10, 10, 10)
                .addComponent(rbtn10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbtn100)
                .addContainerGap(158, Short.MAX_VALUE))
        );
        panelAnchoDeBandaLayout.setVerticalGroup(
            panelAnchoDeBandaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAnchoDeBandaLayout.createSequentialGroup()
                .addGroup(panelAnchoDeBandaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chkAnchoBanda)
                    .addComponent(rbtn10)
                    .addComponent(rbtn100))
                .addContainerGap())
        );

        panelDuplex.setBackground(new java.awt.Color(255, 255, 255));
        panelDuplex.setBorder(javax.swing.BorderFactory.createTitledBorder("Duplex"));

        rbDuplex.setBackground(new java.awt.Color(255, 255, 255));
        rbDuplex.setText("Duplex");
        rbDuplex.setEnabled(false);

        rbFullDuplex.setBackground(new java.awt.Color(255, 255, 255));
        rbFullDuplex.setSelected(true);
        rbFullDuplex.setText("Full Duplex");
        rbFullDuplex.setEnabled(false);

        chkAutoDuplex.setBackground(new java.awt.Color(255, 255, 255));
        chkAutoDuplex.setSelected(true);
        chkAutoDuplex.setText("Auto");
        chkAutoDuplex.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                chkAutoDuplexMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout panelDuplexLayout = new javax.swing.GroupLayout(panelDuplex);
        panelDuplex.setLayout(panelDuplexLayout);
        panelDuplexLayout.setHorizontalGroup(
            panelDuplexLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDuplexLayout.createSequentialGroup()
                .addComponent(chkAutoDuplex)
                .addGap(18, 18, 18)
                .addComponent(rbDuplex)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rbFullDuplex)
                .addContainerGap(114, Short.MAX_VALUE))
        );
        panelDuplexLayout.setVerticalGroup(
            panelDuplexLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDuplexLayout.createSequentialGroup()
                .addGroup(panelDuplexLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chkAutoDuplex)
                    .addComponent(rbDuplex)
                    .addComponent(rbFullDuplex))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        cmbAcces.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Acces", "Trunk" }));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setText("VLAN");

        cmbVLAN.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1:default", "1022:fddi-default", "1003:token-ring-default", "1004:fddinet-default", "1005:trnet-default", " ", " " }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                    .addComponent(panelDuplex, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelAnchoDeBanda, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(cmbAcces, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbVLAN, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(20, 20, 20))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelAnchoDeBanda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelDuplex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cmbAcces, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(cmbVLAN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void chkAnchoBandaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chkAnchoBandaMouseClicked
        
        if(this.chkAnchoBanda.isSelected()) {
            this.rbtn10.setEnabled(false);
            this.rbtn100.setEnabled(false);
            }
        else {
            this.rbtn10.setEnabled(true);
            this.rbtn100.setEnabled(true);
            }
}//GEN-LAST:event_chkAnchoBandaMouseClicked

    private void chkAutoDuplexMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chkAutoDuplexMouseClicked
        if(this.chkAutoDuplex.isSelected()){
        this.rbDuplex.setEnabled(false);
        this.rbFullDuplex.setEnabled(false);
        }
        else{
            this.rbDuplex.setEnabled(true);
            this.rbFullDuplex.setEnabled(true);
        }
    }//GEN-LAST:event_chkAutoDuplexMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgroupDuplex;
    private javax.swing.JCheckBox chkAnchoBanda;
    private javax.swing.JCheckBox chkAutoDuplex;
    private javax.swing.JComboBox cmbAcces;
    private javax.swing.JComboBox cmbVLAN;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JPanel panelAnchoDeBanda;
    private javax.swing.JPanel panelDuplex;
    private javax.swing.JRadioButton rbDuplex;
    private javax.swing.JRadioButton rbFullDuplex;
    private javax.swing.JRadioButton rbtn10;
    private javax.swing.JRadioButton rbtn100;
    // End of variables declaration//GEN-END:variables

}
